home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Format 1997 July
/
macformat52.iso
/
mac
/
Shareware Plus
/
Developers
/
YAAF v1.0 alpha 1
/
(Sources)
/
Standard Controls
/
Buttons
/
XGStdPushButton.cpp
< prev
next >
Wrap
Text File
|
1997-04-24
|
4KB
|
163 lines
/* XGStdPushButton
*
* This puts up a standard push button. This uses the standard
* OS push button if it is available
*/
/* YAAF - Yet another application framework
* Copyright (C) 1997 William Edward Woody and In Phase Consulting
*
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Library
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or any
* later version.
*
* This library is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Library General Public License for
* more details.
*
* You should have received a copy of the GNU Library General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* To contact the author, either e-mail me at
* woody@alumni.caltech.edu, or write to us at
*
* William Edward Woody
* In Phase Consulting
* 1545 Ard Eevin Avenue
* Glendale, CA 91202
*/
#include <XApplication.h>
#include <XStdControls.h>
#include <XStdButtons.h>
#include <XWindow.h>
#include <XError.h>
#include <XDataUtil.h>
/************************************************************************/
/* */
/* Construction/Destruction */
/* */
/************************************************************************/
/* XGStdPushButton::XGStdPushButton
*
* create a push button
*/
XGStdPushButton::XGStdPushButton(XGView *view, XGArgStream &stream) :
XGStdButton(view,stream,true)
{
char title[256];
stream.GetString(sizeof(title),title);
Init(title);
}
XGStdPushButton::XGStdPushButton(XGView *view, XGSButtonInitRecord &i) :
XGStdButton(view,i.v,true)
{
Init(i.title);
}
/* XGStdPushButton::~XGStdPushButton
*
* Delete me
*/
XGStdPushButton::~XGStdPushButton()
{
}
/************************************************************************/
/* */
/* Internal initialization */
/* */
/************************************************************************/
/* XGStdPushButton::Init
*
* The core initialization routine
*/
void XGStdPushButton::Init(char *title)
{
long l;
l = GetParent()->ReceiveDispatch(KEventGetFont,GetViewID(),(void *)&this);
#if OPT_MACOS == 1
XGDraw draw(this,false);
Rect r;
/*
* Create the control at this location
*/
::TextFont(fFont = GETHIWORD(l));
::TextSize(fSize = GETLOWORD(l));
r = GetContentRect();
ViewToGlobal(&r);
fControl = NewControl(GetWindow()->_GetGrafPtr(), // window owner
&r, // where
c2pstr(title), // title
true, // visible
0, // initial value
0, // min value
1, // max value
pushButProc | kControlUsesOwningWindowsFontVariant, // push button proc
0); // refcon
if (fControl == NULL) {
throw XPostError("Unable to make button ^S",p2cstr((unsigned char *)title));
}
#endif
#if OPT_WINOS == 1
Rect r;
HWND w;
/*
* Get the location of the control in the parent's coordinate
* system
*/
r = GetContentRect();
if (GetParent()) {
ViewToGlobal(&r);
GetParent()->GlobalToView(&r);
}
/*
* Create the control window
*/
w = CreateWindow("BUTTON", // control class
title, // control title
WS_CHILD | BS_PUSHBUTTON, // control window flags
r.left,
r.top,
r.right-r.left,
r.bottom-r.top, // control location
GetParent()->_GetHWND(), // container window
NULL, // no menu
_GInstance, // My app instance
NULL); // no additional args
if (w == NULL) {
throw XPostError("Unable to make button ^S",title);
}
_SetHWND(w); // set me as the window
SetProp(w,_GViewClass,(HANDLE)this);
if (IsVisible()) ShowWindow(w,SW_SHOW);
EnableWindow(w,IsEnabled()); // set me up
#endif
}